package jdkc;

import util.JDBCUtils;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

/*
 *@Student 张策
 */
public class jdbc4 {
    public static void main(String[] args) {
        List<Acc> findall = new jdbc4().findall();
        System.out.println(findall);
    }
    public List<Acc>findall(){
        List<Acc> list = new ArrayList<>();
        Statement statement=null;
        ResultSet re=null;
        Connection connection=null;
        try {
            //2.获取数据库连接对象
            connection = JDBCUtils.getConnection();
            //3.定义sql语言
            String mysql="select*from acc";
            //获取执行sql的对象 statement
            statement = connection.createStatement();
            //执行sql
            re = statement.executeQuery(mysql);
            Acc acc=null;
            while (re.next()){
                int anInt = re.getInt("id");
                String string = re.getString("name");
                int anInt1 = re.getInt("account");
                acc = new Acc();
                acc.setId(anInt1);
                acc.setName(string);
                acc.setId(anInt1);
                list.add(acc);
            }
        }  catch (SQLException e) {
            e.printStackTrace();
        }finally {
            JDBCUtils.close(re,statement,connection);
        }
        return list;
    }
}
class Acc {
    private int id;
    private String name;
    private int money;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getMoney() {
        return money;
    }

    public void setMoney(int money) {
        this.money = money;
    }

    @Override
    public String toString() {
        return "acc{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", money=" + money +
                '}';
    }
}